package com.inspur.cloud.controller.auth;

import com.inspur.cloud.entity.dataspace.common.OpResult;
import com.inspur.cloud.entity.dataspace.vo.auth.PowerVO;
import com.inspur.cloud.exception.ApiException;
import com.inspur.cloud.service.dataspace.PowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dataspace/api/v1/power")
@Api(value = "power", description = "权限控制")
public class PowerController {

    @Autowired
    private PowerService powerService;

    @PostMapping("/with")
    public OpResult with(@ApiParam(value = "权限参数") @RequestBody PowerVO powerVO) {
        if (powerVO == null || powerVO.getResourceId() == null || powerVO.getResourceId() <= 0 || powerVO.getType() == null) {
            throw new ApiException("参数不正确");
        }
        OpResult result = new OpResult();
        powerService.oper(powerVO);
        result.setCode(1);
        result.setMsg("操作成功");
        return result;
    }
}
